﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Xml.Linq;
using eschoolBO;

namespace ESCHOOL.admin
{
    public partial class WebForm28 : System.Web.UI.Page
    {
        calender cal = new calender();
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                btnupdate.Visible = false;
                for (int i = 1; i < 31; i++)
                    dddate.Items.Add(i.ToString());
                for (int j = 1950; j < 2050; j++)
                    ddyear.Items.Add(j.ToString());

                DataTable dt = cal.GetRecords(-99, "", "", false, " and ");
                GridView1.DataSource = dt;
                GridView1.DataBind();
            }
        }

        protected void btninsert_Click(object sender, EventArgs e)
        {
            cal.calender_id = -99;
            DateTime dat = new DateTime(Convert.ToInt32(ddyear.SelectedItem.ToString()), Convert.ToInt32(ddmonth.SelectedValue.ToString()), Convert.ToInt32(dddate.SelectedItem.ToString()));
            cal.date = dat.ToString();
            cal.event_name = tbevent.Text;
            cal.isdeleted = false;
            cal.SaveRecords();
            Response.Redirect("~/admin/Calender.aspx");
        }

        protected void btnupdate_Click(object sender, EventArgs e)
        {
            cal.calender_id = -99;
            DateTime dat = new DateTime(Convert.ToInt32(ddyear.SelectedItem.ToString()), Convert.ToInt32(ddmonth.SelectedValue.ToString()), Convert.ToInt32(dddate.SelectedItem.ToString()));
            cal.date = dat.ToString();
            cal.event_name = tbevent.Text;
            cal.isdeleted = false;
            cal.SaveRecords();
            Response.Redirect("~/admin/Calender.aspx");
        }

        protected void btnedit_Command(object sender, CommandEventArgs e)
        {
            btninsert.Visible = false; btnupdate.Visible = true;
            DataTable dt = cal.GetRecords(Convert.ToInt64(e.CommandArgument), "", "", false, " and ");
            tbcalid.Text = dt.Rows[0]["calender_id"].ToString();
            DateTime dat1 = new DateTime();
            dat1=Convert.ToDateTime(dt.Rows[0]["date"].ToString());
            tbevent.Text = dt.Rows[0]["event_name"].ToString();

        }

        protected void btndelete_Command(object sender, CommandEventArgs e)
        {
            if (e.CommandName == "Delete")
            {
                DataTable dt = cal.GetRecords(Convert.ToInt64(e.CommandArgument), "", "", false, " and ");
               cal.calender_id = Convert.ToInt64(dt.Rows[0]["calender_id"].ToString());
               cal.date = dt.Rows[0]["date"].ToString();
                cal.event_name= dt.Rows[0]["event_name"].ToString();
                cal.isdeleted = true;
                cal.SaveRecords();
                Response.Redirect("~/admin/calender.aspx");
            }
        }

        protected void dddate_SelectedIndexChanged(object sender, EventArgs e)
        {

        }

        protected void ddmonth_SelectedIndexChanged(object sender, EventArgs e)
        {

        }

        protected void ddyear_SelectedIndexChanged(object sender, EventArgs e)
        {

        }

        protected void GridView1_RowEditing(object sender, GridViewEditEventArgs e)
        {

        }

        protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e)
        {

        }
    }
}
